# my_tkinter.py
# 用于以后更新GUI

import tkinter as tk
import tkinter.filedialog as fd
from tkinter import ttk
from abc import ABC, abstractmethod


class MyApp(ABC):
    """
    抽象类，用于创建GUI
    需要实现process方法
    """

    options1 = []
    options2 = []
    options3 = []

    def __init__(self, root , options1 = [] , options2 = []):
        MyApp.options1 = options1
        MyApp.options2 = options2

        # 创建窗口
        self.root = root
        self.root.title('Hello World')
        self.root.geometry('400x500')

        self.page1 = tk.Frame(root)
        self.page2 = tk.Frame(root)
        
        self.main_page(self.page1)
        self.setting_page(self.page2)

        self.page1.place(x=0, y=0, relwidth=1, relheight=1)
        self.page2.place(x=0, y=0, relwidth=1, relheight=1)
        self.page1.tkraise()

    def main_page(self,page : tk.Frame):
        '''
        主页面布局设置
        '''
        # 第一行，标题
        self.label = ttk.Label(page, text="欢迎使用我的工具",font=('Arial', 16))
        self.label.pack(pady=10)

        # 第二行，输入框
        self.a_frame1 = ttk.Frame(page)
        self.label1 = ttk.Label(self.a_frame1, text="输入目标文件夹:",font=('Arial', 10))
        self.entry1 = ttk.Combobox(self.a_frame1, width=25,values=MyApp.options1)
        self.file = ttk.Button(self.a_frame1, text="...", command=lambda: self.file_select(self.entry1),width=4)
        
        self.label1.pack(padx=10,side=tk.LEFT)
        self.entry1.pack(side=tk.LEFT)
        self.file.pack(side=tk.LEFT)
        self.a_frame1.pack(pady=5)

        # 第三行，输入框
        self.a_frame2 = ttk.Frame(page)
        self.label2 = ttk.Label(self.a_frame2, text="输入输出文件夹:",font=('Arial', 10))
        self.entry2 = ttk.Combobox(self.a_frame2, width=25,values=MyApp.options2)
        self.file = ttk.Button(self.a_frame2, text="...", command=lambda: self.file_select(self.entry2),width=4)
        
        self.label2.pack(padx=10,side=tk.LEFT)
        self.entry2.pack(side=tk.LEFT)
        self.file.pack(side=tk.LEFT)
        self.a_frame2.pack(pady=5)

        # 第四行，按钮
        self.button = ttk.Button(page, text="执行", command=self.process)
        self.button.pack(pady=10)

        # 第五行，输出框
        self.text = tk.Text(page, height=1000,width=50)
        self.text.pack(pady=10)

        # placce布局
        self.button_enter_setting = ttk.Button(page, text="设置", command=self.page2.tkraise)
        self.button_enter_setting.place(x=10,y=10,width=50,height=30)

    def setting_page(self,page : tk.Frame):
         # 第一行，标题
        self.label_set = ttk.Label(page, text="确认后缀名",font=('Arial', 16))
        self.label_set.pack(pady=10)

        # 第二行，输入框
        self.a_frame1_set = ttk.Frame(page)
        self.label1_set = ttk.Label(self.a_frame1_set, text="输如后缀名:",font=('Arial', 10))
        self.entry1_set = ttk.Combobox(self.a_frame1_set, width=25,values=MyApp.options3)
        
        self.label1_set.pack(padx=10,side=tk.LEFT)
        self.entry1_set.pack(side=tk.LEFT)
        self.a_frame1_set.pack(pady=5)

        # 第三行，按钮
        self.button_frame_set = ttk.Frame(page)
        self.button_add_set = ttk.Button(self.button_frame_set, text="添加", command=self.setadd)
        self.button_remove_set = ttk.Button(self.button_frame_set, text="删除", command=self.setremove)
        self.button_add_set.pack(padx = 10,side=tk.LEFT)
        self.button_remove_set.pack(padx=10,side=tk.LEFT)
        self.button_frame_set.pack(pady=5)

        # 第四行，text
        self.text_set = tk.Text(page, height=1000,width=50)
        self.text_set.pack(pady=10)

        # place 布局
        self.button_back = ttk.Button(page, text="返回", command=self.page1.tkraise)
        self.button_back.place(x=10,y=10,width=50,height=30)

    def file_select(self,enter : tk.Entry):
        file_path = fd.askdirectory()
        print("选择的文件:", file_path)
        enter.insert(0,file_path)


    @abstractmethod
    def process(self):
        pass

    @abstractmethod
    def setadd(self):
        pass

    @abstractmethod
    def setremove(self):
        pass
        




# if __name__ == '__main__': 
#     root = tk.Tk()
#     app = MyApp(root)
#     root.mainloop()


